package algorithm;

import java.util.*;

/**
 * Created by Administrator on 2017/7/5.
 * 这个解决猜字谜的游戏 但是需要一个字典验证单词 因此，暂时搁置，等有时间的话，
 * 我会寻找载入字典库以及验证的方法
 */
public class Anagrammatism {
    //准备素材
    public static char[][] prepareMaterial(){
        char[][] sheet ={{'t','h','i','a'},{'w','a','t','s'},
                         {'o','a','h','g'},{'f','g','d','t'}};
//        System.out.println(Arrays.toString(sheet));
        for (int i=0;i<sheet.length;i++){
            System.out.println(Arrays.toString(sheet[i]));
        }
        return null;
    }

    //制造单词组合 横向 纵向 对角方向
    public static Set<String> makeWords(char[][] sheet){
        Set<String> possibleWords = new HashSet<>();

        //横向词组集合
        for (int i=0;i<sheet.length;i++){
            possibleWords.add(String.valueOf(sheet[i]));
        }
        //纵向集合
        String temp="";
        for (int i=0;i<sheet.length;i++){
            for (int j = 0; j < sheet[i].length; j++) {
                temp += String.valueOf(sheet[i][j]);
            }
            possibleWords.add(temp);
            temp = "";
        }

        //对角方向
        for (int i = 0; i < sheet.length; i++) {
           temp += sheet[i][i];
        }
        possibleWords.add(temp);
        temp = "";

        for (int i = sheet.length-1; i >=0 ; i--) {
            temp += sheet[i][i];
        }
        possibleWords.add(temp);
        temp = "";

        return possibleWords;
    }

    //如何验证字符串是否为单词
    public static String[] getCorrectWords(Set<String> words){
        List<String> forTest = new ArrayList<>();
       //将每一个字符串拆出来，形成更小的单词组合
        for (String word: words){
            for (int i=0;i<word.length()-2;i++){
                for (int j = i+2; j <word.length() ; j++) {
                    forTest.add(word.substring(i,j));
                }
            }
        }

        for (String word: forTest){
            //这里需要一个单词字典
        }

        return null;
    }

    public static void main(String[] args) {
//        prepareMaterial();
        Set<String> potentialWords = makeWords(prepareMaterial());
        getCorrectWords(potentialWords);
    }
}
